package com.ddm.controller;

import com.ddm.service.IProfitService;
import com.dto.AjaxResult;
import com.entity.Profit;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/profit")
public class ProfitController {

    @Autowired
    private IProfitService profitService;

    // 新增业绩
    @PostMapping
    public AjaxResult addProfit(@RequestBody Profit profit) {
        int rows = profitService.insertProfit(profit);
        return rows > 0 ? AjaxResult.success("新增业绩成功") : AjaxResult.error("新增业绩失败");
    }

    // 分页查询业绩
    @GetMapping("/page")
    public AjaxResult page(@RequestParam("pageNum") Integer pageNum,
                           @RequestParam("pageSize") Integer pageSize,
                           @RequestParam(required = false) Profit profit) {
        PageHelper.startPage(pageNum, pageSize);
        List<Profit> list = profitService.selectProfitList(profit);
        PageInfo<Profit> pageInfo = new PageInfo<>(list);
        return AjaxResult.success(pageInfo);
    }
}